package com.cs.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cs.domain.entity.Goods;
import com.cs.goods.vo.GoodsVo;
import com.cs.goods.dao.IGoodsDao;
import com.cs.goods.dao.IGoodsVoDao;
import com.cs.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {
    @Autowired
    IGoodsDao iGoodsDao;
    @Autowired
    IGoodsVoDao iGoodsVoDao;

    @Override
    public List<Goods> findGoods() {
        return iGoodsDao.selectList(null);
    }

    @Override
    public List<GoodsVo> findGoodsVo(String goodsName,Long goodsTypeId) {
        LambdaQueryWrapper<GoodsVo> wrapper = new LambdaQueryWrapper<>();
        if(goodsName!=null){
            wrapper.like(GoodsVo::getGoodsName,goodsName);
        }
        if(goodsTypeId!=null){
            wrapper.eq(GoodsVo::getGoodsTypeId,goodsTypeId);
        }
        return iGoodsVoDao.selectList(wrapper);
    }

    @Override
    public void addGoods(Goods goods) {
        iGoodsDao.insert(goods);
    }

    @Override
    public void updateGoods(Goods goods) {
        iGoodsDao.updateById(goods);
    }

    @Override
    public void delGoods(Long goodsId) {
        iGoodsDao.deleteById(goodsId);
    }
}
